<template>
  <div class="hero-swiper">
    <el-carousel 
      :interval="4000"
      :height="swiperHeight"
      indicator-position="inside"
      arrow="hover"
      class="hero-carousel"
    >
      <el-carousel-item
        v-for="item in bannerList"
        :key="item.id"
        class="carousel-item"
      >
        <div class="banner-content">
          <div class="banner-background">
            <img :src="item.backgroundImage" alt="背景" class="bg-image" />
          </div>
          <div class="banner-text">
            <h2 class="main-title">{{ item.title }}</h2>
            <p class="sub-title">{{ item.subtitle }}</p>
            <button class="action-btn" @click="handleBannerAction(item)">
              {{ item.buttonText }}
            </button>
          </div>
          <div class="banner-decoration">
            <img :src="item.decorationImage" alt="装饰" class="decoration-image" />
          </div>
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

const swiperHeight = ref('140px')

// 轮播图数据
const bannerList = ref([
  {
    id: 1,
    title: '硅谷家装',
    subtitle: '满1000元装修基金',
    buttonText: '立即领取',
    backgroundImage: '/src/assets/imgs/background.png',
    decorationImage: '/src/assets/imgs/foreground.png',
    backgroundColor: 'linear-gradient(135deg, #4CAF50 0%, #8BC34A 100%)'
  },
  {
    id: 2,
    title: '品质装修',
    subtitle: '专业设计师服务',
    buttonText: '免费咨询',
    backgroundImage: '/src/assets/imgs/service_bg.png',
    decorationImage: '/src/assets/imgs/crown.svg',
    backgroundColor: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'
  },
  {
    id: 3,
    title: 'VIP服务',
    subtitle: '尊享一对一服务',
    buttonText: '立即开通',
    backgroundImage: '/src/assets/imgs/vip_bg.png',
    decorationImage: '/src/assets/imgs/vip.png',
    backgroundColor: 'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)'
  }
])

const handleBannerAction = (item) => {
  ElMessage.success(`${item.buttonText}成功！`)
  console.log('Banner点击:', item)
}

// 响应式高度调整
const adjustHeight = () => {
  const screenWidth = window.innerWidth
  if (screenWidth < 768) {
    swiperHeight.value = '120px'
  } else {
    swiperHeight.value = '140px'
  }
}

onMounted(() => {
  adjustHeight()
  window.addEventListener('resize', adjustHeight)
})
</script>

<style scoped>
.hero-swiper {
  margin: 0 16px 20px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.hero-carousel {
  border-radius: 16px;
}

.carousel-item {
  width: 100%;
  height: 100%;
  border-radius: 16px;
}

.banner-content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-radius: 16px;
  overflow: hidden;
}

/* 为每个轮播项设置不同的背景色 */
.carousel-item:nth-child(1) .banner-content {
  background: linear-gradient(135deg, #4CAF50 0%, #8BC34A 100%);
}

.carousel-item:nth-child(2) .banner-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.carousel-item:nth-child(3) .banner-content {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.banner-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0.3;
  border-radius: 16px;
}

.bg-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 16px;
}

.banner-text {
  position: relative;
  z-index: 2;
  color: white;
}

.main-title {
  font-size: 24px;
  font-weight: bold;
  margin: 0 0 8px 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.sub-title {
  font-size: 14px;
  margin: 0 0 16px 0;
  opacity: 0.9;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.action-btn {
  background-color: #fff;
  color: #333;
  border: none;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.action-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  background-color: #f8f9fa;
}

.action-btn:active {
  transform: translateY(0);
}

.banner-decoration {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
}

.decoration-image {
  width: 80px;
  height: 80px;
  object-fit: contain;
  opacity: 0.8;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

/* Element Plus carousel 样式重写 */
:deep(.el-carousel__indicator) {
  width: 8px !important;
  height: 8px !important;
  border-radius: 50% !important;
  background-color: rgba(255, 255, 255, 0.5) !important;
  margin: 0 4px !important;
}

:deep(.el-carousel__indicator.is-active) {
  background-color: #fff !important;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3) !important;
}

:deep(.el-carousel__indicators--horizontal) {
  bottom: 12px !important;
}

:deep(.el-carousel__arrow) {
  background-color: rgba(255, 255, 255, 0.3) !important;
  border: none !important;
  width: 36px !important;
  height: 36px !important;
  border-radius: 50% !important;
}

:deep(.el-carousel__arrow:hover) {
  background-color: rgba(255, 255, 255, 0.5) !important;
}

:deep(.el-carousel__arrow i) {
  color: #fff !important;
  font-weight: bold !important;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .hero-swiper {
    margin: 0 12px 16px;
  }
  
  .banner-content {
    padding: 16px;
  }
  
  .main-title {
    font-size: 20px;
  }
  
  .sub-title {
    font-size: 12px;
  }
  
  .action-btn {
    padding: 6px 16px;
    font-size: 12px;
  }
  
  .decoration-image {
    width: 60px;
    height: 60px;
  }
  
  .banner-decoration {
    right: 16px;
  }
}
</style>
